package com.feihao.zhou.concurrentHashMapTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapTest {
    public static void main(String[] args) throws InterruptedException {

//        ConcurrentHashMap<Integer,Integer> map = new ConcurrentHashMap<>();
//        HashMap<String, String> map = new HashMap<>();
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();

        //创建两个线程，向集合添加元素：
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    map.put(i+"", i+"");
                }
            }
        }).start();

        new Thread(() -> {
            for (int i = 50; i < 101; i++) {
                map.put(i+"", i+"");
            }
        }).start();

        new Thread(() -> {
            for (int i = 101; i < 201; i++) {
                map.put(i+"", i+"");
            }
        }).start();

        Thread.sleep(1000);
        //打印map的value
        for (int i = 0; i < 200; i++) {
            System.out.println(map.get(i+""));
        }


    }
}
